package thread;

import javax.xml.bind.DatatypeConverter;

public class ThreadCallback {
	private String fileName;
	private byte[] digest;
	
	
	public ThreadCallback(String fileName) {
		this.fileName = fileName;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public byte[] getDigest() {
		return digest;
	}
	public void setDigest(byte[] digest) {
		this.digest = digest;
	}
	/**
	 * 计算文件摘要
	 */
	public void calculateDigest(){
		Thread thread = new Thread(new DigestUtil(fileName, this));
		thread.start();
	}
	
	public void receiverDigest(byte[] digest){
		this.digest = digest;
		System.out.println(this);
	}
	
	public String toString() {
		StringBuilder builder = new StringBuilder(fileName+"文件的摘要为");
		builder.append(":");
		builder.append(DatatypeConverter.printHexBinary(this.digest));
		return builder.toString();
	}
	
	public static void main(String[] args) {
		ThreadCallback callback = new ThreadCallback("test.txt");
		callback.calculateDigest();
	}
}
